/*
 * Copyright (c) 2017,安徽皖通科技股份有限公司 All rights reserved.
 */

package com.wttech.dzzf.process.service.test;

import com.wtkj.vo.dzzf.base.kfwd.CardInfo;
import com.wtkj.vo.dzzf.base.kfwd.VehicleInfo;
import com.wttech.dzzf.process.dao.CbcBankDataCheckDao;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.wttech.dzzf.check.moduleSet.CheckCardUpload_10.*;
import static com.wttech.dzzf.process.constant.UserConstants.DEFAULT_VEHICLE_CHAR;
import static com.wttech.dzzf.process.constant.UserConstants.RIGHT;

/**
 * 卡片信息检测
 *
 * @author MaShibo
 * @date 2017/12/6.
 */
@Service
public class CardInfoCheck {

	private static final Logger CARD = LoggerFactory.getLogger("Card");

	private static final Logger LOGGER = LoggerFactory.getLogger(CardInfoCheck.class);

	@Resource
	private CbcBankDataCheckDao cbcBankDataCheckDao;

	@Resource
	private VehicleInfoCheck vehicleInfoCheck;

	void checkCardInfo(CardInfo cardInfo) {
		String cardInfoId = StringUtils.trim(cardInfo.getCardInfoId());

		String result;

		String cardId = StringUtils.trim(cardInfo.getCardNetID() + cardInfo.getECardNo());
		int brand = cardInfo.getCardBrand();
		String model = cardInfo.getCardModel();
		String vehicleId = cardInfo.getVehiclePlate() + DEFAULT_VEHICLE_CHAR + cardInfo.getVehicleColor();

		result = checkId(cardId);
		if (!StringUtils.equalsIgnoreCase(result, RIGHT)) {
			CARD.info("卡片信息【{}】，卡片编号【{}】错误【{}】", new Object[]{cardInfoId, cardId, result});
		}

		result = checkBrand(brand);
		if (!StringUtils.equalsIgnoreCase(result, RIGHT)) {
			CARD.info("卡片信息【{}】，卡品牌【{}】错误【{}】", new Object[]{cardInfoId, brand, result});
		}

		result = checkModel(model);
		if (!StringUtils.equalsIgnoreCase(result, RIGHT)) {
			CARD.info("卡片信息【{}】，卡型号【{}】错误【{}】", new Object[]{cardInfoId, model, result});
		}

		result = checkVehicleId(vehicleId);
		if (!StringUtils.equalsIgnoreCase(result, RIGHT)) {
			CARD.info("卡片信息【{}】，车牌信息【{}】错误【{}】", new Object[]{cardInfoId, vehicleId, result});
		}

		VehicleInfo vehicleInfo = cbcBankDataCheckDao.queryVehInfosByVeh(cardInfo.getVehiclePlate(), cardInfo.getVehicleColor());
		if (vehicleInfo == null) {
			LOGGER.info("卡片信息【{}】，车牌号【{}】，车牌颜色【{}】没有对应的车辆信息", new Object[]{cardInfoId, cardInfo.getVehiclePlate(), cardInfo.getVehicleColor()});
		} else {
			vehicleInfoCheck.checkVehicle(vehicleInfo);
		}
	}

}
